using System.Security.Cryptography;
using System.Text;

namespace FastDevTemplate.Common.Util;

public static class EncryptionTool
{
    public static string ComputeSha1Hash(string rawData)
    {
        // 创建一个 SHA1CryptoServiceProvider 对象
        var sha1 = SHA1.Create();

        // 计算给定字符串的 SHA-1 哈希值
        var bytes = Encoding.UTF8.GetBytes(rawData);
        var hashBytes = sha1.ComputeHash(bytes);

        // 将字节数组转换为十六进制字符串
        var builder = new StringBuilder();
        for (var i = 0; i < hashBytes.Length; i++)
            builder.Append(hashBytes[i].ToString("x2"));
        return builder.ToString();
    }
}